<template>
    <div>
        <van-nav-bar title="充值中" left-text="返回" left-arrow @click-left="onClickLeft" />
    </div>
    <div style="text-align: center;margin-top: 50px;">
        <!-- <van-loading type="spinner" color="#1989fa" size="36px">充值中</van-loading> -->
        <van-loading size="36px" text-color="#0094ff" vertical>充值中...</van-loading>
    </div>
</template>

<script setup>
import router from '@/router';
import { ref , onBeforeMount } from 'vue';
import { PaymentNotify } from '@/api/pay.js';

import { useRoute } from 'vue-router';
const route = useRoute();
var isSuccess = ref(true)

const onClickLeft = () => history.back();
setTimeout(() => {
    // 假设你有一个方法可以决定是跳转到成功页面还是失败页面
    navigateToSuccessOrFailurePage();
}, 3000); // 三秒后执行
var payment=ref({
    outTradeNo:'',
    tradeState:'SUCCESS'
})
onBeforeMount(() => {
    payment.value.outTradeNo=route.query.outTradeNo;
});

function navigateToSuccessOrFailurePage() {
    console.info(payment.value)
    // 返回订单，查询订单状态
    // 假设存在一个判断成功与否的逻辑或者标记 this.isSuccess
    if (isSuccess.value) {
        PaymentNotify(payment.value)
            .then(res => {
                console.info(res)
            })
        // 跳转到成功页面
        router.push('/user/charge/money/success')
    } else {
        // 跳转到失败页面
        router.push('/user/charge/money/failed')
    }
}
</script>